"""
Case Type   : tools
Case Name   : pg_controldata使用-?查看帮助信息
Create At   : 2021/1/28
Owner       : opentestcase003
Description :
    1.使用-V参数执行pg_controldata
    pg_controldata -?
    2.信息是否查询成功
    3.使用--help参数执行pg_controldata
    pg_controldata --help
    4.信息是否查询成功
Expect      :
    1.使用-?参数执行pg_controldata成功
    2.信息查询成功
    3.使用-help参数执行pg_controldata成功
    4.信息查询成功
History     :
    modified by opentestcase012 at 2022-11-15:代码变更,修改help断言,优化用例
"""
import os
import unittest
from yat.test import Node
from yat.test import macro
from testcase.utils.Logger import Logger


class Tools(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'-----{os.path.basename(__file__)} start-----')
        self.userNode = Node('PrimaryDbUser')
        self.DB_ENV_PATH = macro.DB_ENV_PATH

    def test_systools(self):
        self.logger.info('--------查看帮助信息--------')
        help_msg = ['-V, --version     output version information, then exit',
                    '-?, --help        show this help, then exit',
                    '-I, --instance-id=INSTANCE_ID',
                    'display information of specified instance (default all)',
                    '--enable-dss  enable shared storage mode',
                    '--socketpath=SOCKETPATH', 'dss connect socket file path']
        excute_cmd1 = f'source {self.DB_ENV_PATH};pg_controldata -?'
        self.logger.info(excute_cmd1)
        msg1 = self.userNode.sh(excute_cmd1).result()
        self.logger.info(msg1)
        for content in (help_msg):
            self.logger.info(content)
            self.assertTrue(msg1.find(content) > -1)
        excute_cmd2 = f'source {self.DB_ENV_PATH};pg_controldata --help'
        self.logger.info(excute_cmd2)
        msg2 = self.userNode.sh(excute_cmd2).result()
        self.logger.info(msg2)
        for content in (help_msg):
            self.logger.info(content)
            self.assertTrue(msg1.find(content) > -1)

    def tearDown(self):
        self.logger.info('----清理环境----')
        self.logger.info(f'-----{os.path.basename(__file__)} end-----')
